require "import" import "android.view.*" import "android.widget.*" import "com.androlua.*" import "android.media.*" import "java.io.*" local audiomanager=AudioManager(this) local function playSoundPreviewVolume(a,b) local filePath="/system/media/audio/ui/"..a local file=File(filePath) if file.exists() if mediaplayer mediaplayer.stop() end mediaplayer=MediaPlayer() mediaplayer.setAudioAttributes(AudioAttributes.Builder() .setUsage(b) .build()) mediaplayer.setDataSource(filePath) mediaplayer.prepare() mediaplayer.start() mediaplayer.setOnCompletionListener( {onCompletion=function mediaplayer.release() mediaplayer=nil selectedSeekBar=nil end }) end end selectedSeekBar=nil local dlgVolume=LuaDialog(this) dlgVolume.View=loadlayout({LinearLayout,orientation="vertical",{TextView,text="Aksesibilitas",textSize="20sp",layout_width="fill",layout_height="wrap"},{SeekBar,id="seekBar1",layout_width="fill",layout_height="wrap",progress=audiomanager.getStreamVolume(audiomanager.STREAM_ACCESSIBILITY),max=audiomanager.getStreamMaxVolume(audiomanager.STREAM_ACCESSIBILITY)},{TextView,text="Alarm",textSize="20sp",layout_width="fill",layout_height="wrap"},{SeekBar,id="seekBar2",layout_width="fill",layout_height="wrap",progress=audiomanager.getStreamVolume(audiomanager.STREAM_ALARM),max=audiomanager.getStreamMaxVolume(audiomanager.STREAM_ALARM)},{TextView,text="Media",textSize="20sp",layout_width="fill",layout_height="wrap"},{SeekBar,id="seekBar3",layout_width="fill",layout_height="wrap",progress=audiomanager.getStreamVolume(audiomanager.STREAM_MUSIC),max=audiomanager.getStreamMaxVolume(audiomanager.STREAM_MUSIC)},{TextView,text="Notifikasi",textSize="20sp",layout_width="fill",layout_height="wrap"},{SeekBar,id="seekBar4",layout_width="fill",layout_height="wrap",progress=audiomanager.getStreamVolume(audiomanager.STREAM_NOTIFICATION),max=audiomanager.getStreamMaxVolume(audiomanager.STREAM_NOTIFICATION)},{TextView,text="Nada dering",textSize="20sp",layout_width="fill",layout_height="wrap"},{SeekBar,id="seekBar5",layout_width="fill",layout_height="wrap",progress=audiomanager.getStreamVolume(audiomanager.STREAM_RING),max=audiomanager.getStreamMaxVolume(audiomanager.STREAM_RING)},{TextView,text="Panggilan",textSize="20sp",layout_width="fill",layout_height="wrap"},{SeekBar,id="seekBar6",layout_width="fill",layout_height="wrap",progress=audiomanager.getStreamVolume(audiomanager.STREAM_VOICE_CALL),max=audiomanager.getStreamMaxVolume(audiomanager.STREAM_VOICE_CALL)},{TextView,text="SYSTEM",textSize="20sp",layout_width="fill",layout_height="wrap"},{SeekBar,id="seekBar7",layout_width="fill",layout_height="wrap",progress=audiomanager.getStreamVolume(audiomanager.STREAM_SYSTEM),max=audiomanager.getStreamMaxVolume(audiomanager.STREAM_SYSTEM)}}) dlgVolume.setTitle"Volume" dlgVolume.setButton("Tutup",function if mediaplayer mediaplayer.release() mediaplayer=nil end end) dlgVolume.show() seekBar1.setOnSeekBarChangeListener({onProgressChanged=function(a,b,c) audiomanager.setStreamVolume(audiomanager.STREAM_ACCESSIBILITY,b,audiomanager.FLAG_REMOVE_SOUND_AND_VIBRATE) end,onStartTrackingTouch=function service.playSoundGestureBegin() if selectedSeekBar=="seekBar1" else playSoundPreviewVolume("Media_preview_Over_the_horizon.ogg",AudioAttributes.USAGE_ASSISTANCE_ACCESSIBILITY) end selectedSeekBar="seekBar1" end,onStopTrackingTouch=function service.playSoundGestureEnd() end}) seekBar2.setOnSeekBarChangeListener({onProgressChanged=function(a,b,c) audiomanager.setStreamVolume(audiomanager.STREAM_ALARM,b,audiomanager.FLAG_REMOVE_SOUND_AND_VIBRATE) end,onStartTrackingTouch=function service.playSoundGestureBegin() if selectedSeekBar=="seekBar2" else playSoundPreviewVolume("Media_preview_Over_the_horizon.ogg",AudioAttributes.USAGE_ALARM) end selectedSeekBar="seekBar2" end,onStopTrackingTouch=function service.playSoundGestureEnd() end}) seekBar3.setOnSeekBarChangeListener({onProgressChanged=function(a,b,c) audiomanager.setStreamVolume(audiomanager.STREAM_MUSIC,b,audiomanager.FLAG_REMOVE_SOUND_AND_VIBRATE) end,onStartTrackingTouch=function service.playSoundGestureBegin() if selectedSeekBar=="seekBar3" else playSoundPreviewVolume("Media_preview_Over_the_horizon.ogg",AudioAttributes.USAGE_MEDIA) end selectedSeekBar="seekBar3" end,onStopTrackingTouch=function service.playSoundGestureEnd() end}) seekBar4.setOnSeekBarChangeListener({onProgressChanged=function(a,b,c) audiomanager.setStreamVolume(audiomanager.STREAM_NOTIFICATION,b,audiomanager.FLAG_REMOVE_SOUND_AND_VIBRATE) end,onStartTrackingTouch=function service.playSoundGestureBegin() if selectedSeekBar=="seekBar4" else playSoundPreviewVolume("Media_preview_Over_the_horizon.ogg",AudioAttributes.USAGE_NOTIFICATION) end selectedSeekBar="seekBar4" end,onStopTrackingTouch=function service.playSoundGestureEnd() end}) seekBar5.setOnSeekBarChangeListener({onProgressChanged=function(a,b,c) audiomanager.setStreamVolume(audiomanager.STREAM_RING,b,audiomanager.FLAG_REMOVE_SOUND_AND_VIBRATE) end,onStartTrackingTouch=function service.playSoundGestureBegin() if selectedSeekBar=="seekBar5" else playSoundPreviewVolume("Media_preview_Over_the_horizon.ogg",AudioAttributes.USAGE_NOTIFICATION_RINGTONE) end selectedSeekBar="seekBar5" end,onStopTrackingTouch=function service.playSoundGestureEnd() end}) seekBar6.setOnSeekBarChangeListener({onProgressChanged=function(a,b,c) audiomanager.setStreamVolume(audiomanager.STREAM_VOICE_CALL,b,audiomanager.FLAG_REMOVE_SOUND_AND_VIBRATE) end,onStartTrackingTouch=function service.playSoundGestureBegin() if selectedSeekBar=="seekBar6" else playSoundPreviewVolume("Media_preview_Over_the_horizon.ogg",AudioAttributes.USAGE_VOICE_COMMUNICATION) end selectedSeekBar="seekBar6" end,onStopTrackingTouch=function service.playSoundGestureEnd() end}) seekBar7.setOnSeekBarChangeListener({onProgressChanged=function(a,b,c) audiomanager.setStreamVolume(audiomanager.STREAM_SYSTEM,b,audiomanager.FLAG_REMOVE_SOUND_AND_VIBRATE) end,onStartTrackingTouch=function service.playSoundGestureBegin() if selectedSeekBar=="seekBar7" else playSoundPreviewVolume("Media_preview_Over_the_horizon.ogg",AudioAttributes.USAGE_ASSISTANCE_SONIFICATION) end selectedSeekBar="seekBar7" end,onStopTrackingTouch=function service.playSoundGestureEnd() end}) return true